package com.wthink.hzgj.menu

import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.Navigation
import androidx.navigation.findNavController
import com.wthink.hzgj.BusApplication
import com.wthink.hzgj.R
import com.wthink.hzgj.databinding.FragmentMenuListBinding
import com.wthink.hzgj.main.CheckinDialog
import com.wthink.hzgj.main.MainActivity
import com.wthink.hzgj.main.viewmodel.CheckinViewModel
import com.wthink.hzgj.menu.viewmodel.MenuListViewModel
import com.wthink.hzgj.util.setBackgroundAlpha
import com.wthink.hzgj.util.toast

class MenuListFragment : Fragment(){

    private val viewModel by viewModels<MenuListViewModel>()

    private lateinit var binding : FragmentMenuListBinding

    private val loginModel by viewModels<LoginModel>()


    private val loginDialog by lazy {
        LoginDialog.make(BusApplication.busContext, binding.root as ViewGroup, loginModel,
            activity as AppCompatActivity
        )
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = DataBindingUtil.inflate(
            inflater,
            R.layout.fragment_menu_list,
            container,
            false
        )
        binding.viewModel = viewModel
        binding.lifecycleOwner = this
        return binding.root
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        //val nav = activity?.let { Navigation.findNavController(it, R.id.main) }

        //返回
        binding.back.setOnClickListener {
            it.findNavController().popBackStack()
        }

        //主界面
        binding.btnMain.setOnClickListener {
            Navigation.findNavController(it).navigate(R.id.homeFragment)
        }

        //设置
        binding.btnSeting.setOnClickListener {
            Navigation.findNavController(it).navigate(R.id.settingsFragment)
        }

        //状态
        binding.btnState.setOnClickListener {
            Navigation.findNavController(it).navigate(R.id.stateFragment)
        }

        //版本
        binding.btnVersion.setOnClickListener {
            Navigation.findNavController(it).navigate(R.id.verisonFragment)
        }

        //调度申请
        binding.btnBusiness.setOnClickListener{
            Navigation.findNavController(it).navigate(R.id.businessFragment)
        }

        //文件COPY
        binding.btnCopy.setOnClickListener{
            //toast(BusApplication.busContext,"暂未开放")
            Navigation.findNavController(it).navigate(R.id.copyFileCameraFragment)
/*            loginDialog.showAtLocation(
                binding.root,
                Gravity.CENTER,
                0,
                0
            )
            setBackgroundAlpha(0.6f)
            viewModel.addList()*/
        }

        //存储介质
        binding.btnSdcard.setOnClickListener{
            Navigation.findNavController(it).navigate(R.id.sdcardFragment)
        }

        //消息列表
        binding.btnMsgList.setOnClickListener{
            Navigation.findNavController(it).navigate(R.id.msgListFragment)
        }
    }
}


